package com.financing.platform.web.api;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.platform.common.ResultCode;
import com.financing.platform.common.ResultMap;
import com.financing.platform.common.ResultMap.STATUS;
import com.financing.platform.dto.SMSADDTO;
import com.financing.platform.service.ISMSADService;
import com.financing.platform.util.DTOdateSet;
import com.financing.platform.util.StringUtil;

@Controller("sMSAdAction")
@RequestMapping("/api/sms")
@Scope("prototype")
public class SMSAdAction  extends BaseAction{
	
	
	@Autowired
	private ISMSADService sMSAdServiceImpl;
	
	@RequestMapping("/smsADList.shtml")
	@ResponseBody
	public ResultMap querySMSADList(HttpServletRequest request,
			HttpServletResponse response) {
		
		try{
			List<SMSADDTO> list = sMSAdServiceImpl.listSmsAd();
			resultMap.setAttribute("list", list);
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
		}catch(Exception e){
			log.error("query order list error",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return resultMap;
	}
	
	@RequestMapping("/updateSMSAD.shtml")
	@ResponseBody
	public ResultMap updateSMSAD(HttpServletRequest request,
			HttpServletResponse response,SMSADDTO smsAdDTO ) {
		
		try{
			
			if(smsAdDTO.getId() == null||StringUtil.isNullOrEmptyStr(smsAdDTO.getSmsType())||StringUtil.isNullOrEmptyStr(smsAdDTO.getSmsRemark())){
				resultMap.setStatus(STATUS.FAILE);
				resultMap.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				return resultMap;
			}
			
			DTOdateSet.setCreateInfo(smsAdDTO, request.getSession());
			DTOdateSet.setUpdateInfo(smsAdDTO, request.getSession());
			sMSAdServiceImpl.updateSmsAd(smsAdDTO);
			resultMap.setAttribute("smsAD", smsAdDTO);
			
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
		}catch(Exception e){
			log.error("query order list error",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		
		return resultMap;
	}
	
}
